<?php
require_once BACKGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class background_order_index_action_service extends background_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {                	                 
        $request_data = $_GET;
        
        //$page_num = 1;
        $page_num = init_user_data_key($request_data, 'page_num', 'int');
        //var_dump($page_num); exit();
        $item_count = 20;
        //$item_count = init_user_data_key($request_data, 'item_count', 'int');
        //var_dump($item_count); exit();
        $page_range = 2;
        //$page_range = init_user_data_key($request_data, 'page_range', 'int');
        //var_dump($page_range); exit();
    
        $where = array();
        //id编号
        $id = init_user_data_key($request_data, 'id', 'int');
        if($id > 0){
            self::add_view_data('id', $id);
            $where['id'] = $id;
        }else{
            self::add_view_data('id', '');
        }
        //sn编号
        $order_sn = init_user_data_key($request_data, 'order_sn', 'str', '');
        self::add_view_data('order_sn', $order_sn);
        if($order_sn !== ''){
            $where['order_sn'] = $order_sn;
        }
        
        //用户id【member_id】
        $member_id = init_user_data_key($request_data, 'member_id', 'int');
        if($member_id > 0){
            self::add_view_data('member_id', $member_id);
            $where['member_id'] = $member_id;
        }else{
            self::add_view_data('member_id', '');
        }                
        
        //状态：10为全部
        $status = init_user_data_key($request_data, 'status', 'int', 10);
        if(!in_array($status, array(10, 0, 1, 2, 3))){
            $status = 10;
        }
        self::add_view_data('status', $status);
        if($status !== 10){
            $where['status'] = $status;
        }
        
        $model_background_order = wwy_resource_container::get_model_background_order();
        //var_dump($model_background_order); exit();
        //$where = array();
        $order = array('id desc');
        $options = array('page_num' => $page_num, 'item_count' => $item_count, 'page_range' => $page_range);
//         $order_list = $model_background_order->fetch_all($where, $order);
//         //var_dump($order_list); exit();
        $list = $model_background_order->get_list($where, $order, $options);
        //var_dump($list); exit();
    
        //$data = array('order_list' => $order_list);
        self::add_view_data('order_list', $list['list']);
        self::add_view_data('page_data', $list['page_data']);
    }
}